home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Presentations / Presentations ’96 / Papers ’96 / Book of Practical Objects / BasicObjects ƒ / TreeNode.h < prev   
Encoding:
Text File  |  1996-04-29  |  2.1 KB  |  66 lines  |  [TEXT/CWIE]

  1. //    TreeNode.h
  2.  
  3. #pragma    once
  4.  
  5. class    TreeNode
  6. {
  7. protected:
  8.     TreeNode    *fParent;
  9.     TreeNode    *fLeftChild;
  10.     TreeNode    *fRightChild;
  11.  
  12.     void*        fNodeKey;
  13.     void*        fNodeData;
  14.     
  15.     long        fLeftChildCount;
  16.     long        fRightChildCount;
  17.  
  18. public:
  19.             // Start with the standard constructors an destructors
  20.             TreeNode(void* theKey);
  21.             TreeNode(void* theKey, void* theData);
  22.     virtual    ~TreeNode(void);
  23.     
  24.             // Create and insert an new node into the tree
  25.     virtual    TreeNode*    InsertNode(void* theKey, void* theData);
  26.     
  27.             // Accessor functions for the keys and data in this tree
  28.             // Note that you can't change the key, since it is unique and
  29.             // that might cause a duplicate to appear. You should delete this
  30.             // node, then re-add the data with the new key.
  31.     virtual    void*    GetNodeKey(void);
  32.     virtual    void*    GetNodeData(void);
  33.     virtual    void    SetNodeData(void* theData);
  34.         
  35.             // Search functions for the tree
  36.     virtual    TreeNode*    FindKeyNode(void* searchKey);
  37.     virtual    TreeNode*    FindDataNode(void* searchData);    // Returns FIRST instance of searchData
  38.  
  39.             // Miscellaneous information methods
  40.     virtual    long    GetChildCount(void);
  41.     long    GetLeftChildCount(void);            // Rarely called by object user
  42.     long    GetRightChildCount(void);            // ditto
  43.  
  44.             // Methods for walking the tree
  45.     virtual    TreeNode*    GetRoot(void);
  46.     virtual    TreeNode*    GetFirstNode(void);        // The first node in-order
  47.  
  48.     virtual    TreeNode*    GetNextNode(void);                // Get the next node AFTER this node in-order
  49.     virtual    TreeNode*    GetPreviousNode(void);            // Get the previous node BEFORE this node
  50.     
  51.             // Utility function to remove an entire sub-tree
  52.     virtual    void    PruneBranch(void);    // Remove this branch and sub-branches from the tree.
  53.  
  54. protected:
  55.     virtual    TreeNode*    GetLeftmostSubNode(void);        // For internal tree walking
  56.     virtual    void    InsertChildLeft(TreeNode *nodePtr);
  57.     virtual    void    InsertChildRight(TreeNode *nodePtr);
  58.     
  59.     virtual    void    DeleteChildLeft();
  60.     virtual    void    DeleteChildRight();
  61.  
  62.     // Returns -1 if compareData < fNodeData, 0 if equal, and 1 if compareData > fNodeData
  63.     virtual    short    CompareToNodeKey(void* compareKey);
  64.     virtual    short    CompareToNodeData(void* compareData);
  65. };
  66.